<?php
$dir=$_GET["dir"];
$allowbrowse= $AllowSelfBrowse || !strstr($dir,basename(dirname($GLOBALS["SCRIPT_FILENAME"])));
?>
<div id="conteudo">
<h2>Administra&ccedil;&atilde;o &raquo; Gerenciador de Arquivos</h2>
<br />
<?php
$hDir=opendir($ROOTPATH.$dir);
if($allowbrowse) {
	print "Conte&uacute;do da pasta ".$dir;
	if(strcmp($dir,'/')) print "/";
}
$j=0;
$frmid=0;
if(strlen($Exceptions)>0) $except=explode(",",$Exceptions);
while ($file=readdir($hDir)) {
	$res=true;
	if(strlen($Exceptions)>0) {
		reset($except);
		for($i=0;$i<count($except);$i++) {
			if(!strcmp($file,$except[$i])) {
				$res=false;
				break;
			}
		}
	}
	if($res) {
		$files[$j++]=$file;
	}
} 
if($allowbrowse) {
	if(strcmp($dir,"/")) 	{
		$updir=dirname($dir);
		$updir=str_replace("\\","/",$updir);
		if($updir=="")
			$updir="/";
		print "<div class='barra'><a href='?aplicativo=$_GET[aplicativo]&amp;subaplicativo=$_GET[subaplicativo]&amp;dir=$updir'><img src='$imagens/icones/updir.png' alt='updir' /></a></div>\n";
	}
	if(count($files)) {
		sort($files);
		reset($files);
	
		print "<table class='table-list'>\n";
		print "  <tr>\n";
		print "    <th colspan='2'>&nbsp;</th>\n";
		print "    <th>Nome</th>\n";
		print "    <th>Modo</th>\n";
		print "    <th>Tamanho</th>\n";
		print "    <th>&Uacute;ltima modifica&ccedil;&atilde;o</th>\n";
	
		print "  </tr>\n";
	
		$i=0;
		while (list($key,$name) = each($files)) {
			$cor = ($coralternada++ %2 ? "#fff" : "#f9f9f9");
			$filename=$ROOTPATH."$dir$sp$name";
			$rc=chkfile($name,&$icon);
	
			if(is_dir($filename)) {
				$filestats=GetFileInfo($filename);
	
				if(!$filestats['ux'] || !$AllowSelfBrowse && !strcmp($name,basename(dirname($GLOBALS["SCRIPT_FILENAME"]))) ) {
					print "<tr style='background-color: $cor;'>\n";
					print "<td>\n";
					print "\t<img src='$imagens/icones/nodir.gif' alt='[private dir]'>&nbsp;$name\n";
					print "</td>\n";
				}
				else {
					print "  <tr>\n";
					print "    <td>\n";

					$href="?aplicativo=$_GET[aplicativo]&amp;subaplicativo=$_GET[subaplicativo]&amp;dir=$dir$sp$name";
					print "\t<a href=\"".$href."\"><img ";
					if($filestats['islnk'])
						print "src='images/icon_dirlnk.gif' alt='[dir link]' /></a>";
					else
						print "src='$imagens/icones/dir.png' alt='[dir]' /></a>";
						
					print "&nbsp;<a href=\"".$href."\">$name</a>\n";
					print "    </td>\n";
				}		
					print "<td>" . $filestats["humanperm"] . "</td>\n";
					print "<td>&nbsp;</td>\n";
					print "<td>" . $filestats["mtime"] . "</td>\n";
					print "</tr>\n";			
					$i++;
			}
		}
		reset($files);
		while (list($key,$name) = each($files)) {
			$rc=chkfile($name,&$icon);
			$filename=$ROOTPATH."$dir$sp$name";
			$href=$ROOTURL."$dir$sp$name";
			$cor = ($coralternada++ %2 ? "#fff" : "#f9f9f9");	
			if(!is_dir($filename)) {
	
				$filestats=GetFileInfo($filename);
				
				print "<tr style='background-color: $cor;'>\n";
				print "<td><a href='delfile.php?dir=$dir&amp;name=$name'><img src='$imagens/delete.png' alt='del' /></a></td>\n";
				print "<td><a href='send.php?filename=$dir$sp$name'><img src='$imagens/enviar.png' alt='env' /></a></td>\n";
				print "<td><a href=\"".$href."\"><img src='$icon' alt='[file]' /></a>";
				print "&nbsp;<a href=\"".$href."\">$name</a>\n";
				print "</td>\n";
				print "<td>" . $filestats["humanperm"] . "</td>\n";
				$s=$filestats["size"];
				$unit="b";
				if($s >= 1024) { 
					$s=floor(round($s/1024));
					$unit="kb";
				}
				if($s>=(1024*1024)) {
					$s=floor(round($s/1048576));
					$unit="Mb";
				}
				print "<td>" . $s.$unit . "</td>\n";
				print "<td>" . $filestats["mtime"] . "</td>\n";
				print "</tr>\n";
			$i++;
			}
		}		
	print "</table>\n\n";
	
	$msg=$i." item";
	if($i>1) $msg.="s";
	print "<div>$msg.</div>\n";
	}	
	else {
		print "<br /><div>[Pasta Vazia]</div>\n";
	}
}
else {
	if(! $pass++) {
	print "<div class='aviso_exclusao'>Sem permiss&otilde;es de acesso para esta pasta.</div>\n";
	}
}

?>
</div>